﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;

using DbSharp.Framework.Driver;

namespace DbSharp.Framework.DbObject
{

    /// <summary>
    /// Argument entity class for one stored procedure 
    /// </summary>
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class StatementArgument
    {
        #region Private members 

        private string m_DirectionStr;
        private ArgumentDirection m_Direction;
        private string m_TypeStr;

        #endregion

      

        #region Public property/method

        public string Name { get; set; }

        public string Value { get; set; }

        /// <summary>
        /// the argument value is come from other statement output recordset.
        /// </summary>
        public string ValueFieldInLookupStatement { get; set; }

        public bool ValueNeedLookUp { get; set; }

        /// <summary>
        /// It is just used for DateTime type argument
        /// </summary>
        public string DataTimeFormat { get; set; }


        public string DirectionStr
        {
            get { return m_DirectionStr; }
            set
            {
                m_DirectionStr = value;
                m_Direction = ArgumentDirectionHelper.ParseDirection(m_DirectionStr);
            }
        }

        public ArgumentDirection Direction
        {
            get { return m_Direction; }
            set { m_Direction = value; }
        }

        public string TypeStr
        {
            get { return m_TypeStr; }
            set { m_TypeStr = value.Trim().ToUpper(); }
        }

        public int Size { get; set; }

        /// <summary>
        /// Indicates this argument is result argument of sql statment or not 
        /// </summary>
        public bool IsSqlStmtResultArg { get; set; }

 

        /// <summary>
        /// Clone a new StatementArgument object
        /// </summary>
        /// <returns></returns>
        public StatementArgument CloneArgument()
        {
            var item = new StatementArgument();
            item.DataTimeFormat = this.DataTimeFormat;
            item.Direction = this.Direction;
            item.DirectionStr = this.DirectionStr;
            item.IsSqlStmtResultArg = this.IsSqlStmtResultArg;
            item.Name = this.Name;
            item.Size = this.Size;
            item.TypeStr = this.TypeStr;
            item.Value = this.Value;
            item.ValueFieldInLookupStatement = this.ValueFieldInLookupStatement;
            item.ValueNeedLookUp = this.ValueNeedLookUp;
            return item;
        }

        #endregion

    }
}
